package view
{
	import events.EventType;
	import events.GameDispatherEvent;
	import events.GameEvent;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import manager.ObjectPool;
	import manager.TankName;
	
	import view.base.BaseView;
	import view.effect.MouseEffect;
	
	public class MouseTipView extends BaseView
	{
		private var mouseTip:DisplayObject;
		
		private var mouseEffect:MouseEffect;

		public function MouseTipView()
		{
			super();
			this.mouseChildren =false;
			this.mouseEnabled = false;
			GameDispatherEvent.addEventListener(EventType.MOUSE_UP,hide);
			mouseEffect = new MouseEffect();
		}
		
		override protected function loop(event:Event):void{
			if(mouseTip){
				mouseTip.x = mouseX;
				mouseTip.y = mouseY;
			}
		}
		
		public function show(type:String):void{	
			mouseTip = ObjectPool.getObj(TankName.getTankClsForClip(type)) as DisplayObject;
			(mouseTip as MovieClip).stop();
			mouseTip.scaleX = 40/mouseTip.height;
			mouseTip.height = 40;
			this.addChild(mouseTip);
		}
		
		public function hide(e:GameEvent):void{
			if(this.parent){
				this.removeChild(mouseTip);
				mouseTip = null;
				mouseEffect.hide();
				this.parent.removeChild(this);
			}
		}
		
		public function showMouseEffect(_x:int,_y:int):void{
			this.addChild(mouseEffect);
			mouseEffect.x =_x;
			mouseEffect.y = _y;
			mouseEffect.play();
		}
	}
}